from symbol import return_stmt

import FindXY
import FindFace
import GetScreen
import GetTxt
import random
import cv2
import pyautogui
import pyperclip

k = 0
maxK = 31

if __name__ == '__main__':


    while True:

        cv2.waitKey(3000)


        # 获取截图
        tempScreenName = "temp/screen" + str(random.randint(1, 1000000)) + ".png"
        GetScreen.capture_screen_and_save(tempScreenName)
        img = cv2.imread(tempScreenName)

        while True:
            # 等待1秒
            cv2.waitKey(3000)

            # 查找是否有点赞
            top_left, bottom_right, center, max_val = FindXY.find_template_in_image("img/huiguan.png",
                                                                                    tempScreenName)

            print(f"点赞位置：{center}")

            if max_val > 0.85:
                print("未点赞")
                cv2.rectangle(img, top_left, bottom_right, (0, 0, 255), 20)

                # 保存更新
                cv2.imwrite(tempScreenName, img)

                if (center[1]) < 230:
                    continue

                # 移动光标并点击
                pyautogui.moveTo(center[0], center[1], duration=0.4)  # duration 是移动所需时间(秒)
                pyautogui.click(center[0], center[1])

                k = k + 1

                if k > maxK :
                    break
            else:
                break

        if k > maxK :
            break
        pyautogui.moveTo(400, 400, duration=0.4)  # duration 是移动所需时间(秒)
        cv2.waitKey(random.randint(1000, 1500))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(1000, 1500))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(1000, 1500))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(1000, 1500))
        pyautogui.scroll(-200)
